<?php

namespace Lib;

class RedisCache extends \Redis {
    private static $obj = null;

    public function __construct() {
        parent::__construct();

        $redisConf = \Lib\Conf::get("redis.default");

        list($host, $port) = explode(':', $redisConf);
        $connectRet = parent::connect($host, $port);
        if (false == $connectRet) {
            echo '连接失败';
            exit;
        }
    }

    /**
     * redis 实例
     *
     * @return null|static
     */

    public static function getRedisInstance() {
        if (!class_exists('Redis')) {
            echo 'Redis基类不存在';
            exit;
        }
        if (self::$obj == null) {
            self::$obj = new static();
        }

        return self::$obj;
    }

}